package me.ratel.demo.wechat;

import me.ratel.demo.wechat.entities.GetMenuResponse;
import me.ratel.demo.wechat.exceptions.InvalidCredentialException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Administrator
 * @time 2016/9/17 14:19
 */
class RetryWeChatServiceImpl extends AbstractWeChatService {
    private static final Logger log = LoggerFactory.getLogger(RetryWeChatServiceImpl.class);

    public RetryWeChatServiceImpl(WeChatService delegate) {
        super(delegate);
    }

    @Override public GetMenuResponse getMenu() {
        int i = 0;
        while (i++ < configuration.getRefreshAccessTokenTimes()){
            try {
                return delegate.getMenu();
            } catch (InvalidCredentialException ice) {
                log.error("", ice);
            }
            /*try {
                Thread.sleep(configuration.getRefreshAccessTokenInterval());
            } catch (InterruptedException ite) {
                log.error("", ite);
            }*/
        }
        return null;
    }
}
